home *** CD-ROM | disk | FTP | other *** search
/ HPAVC / HPAVC CD-ROM.iso / pc / ABUSESRC.ZIP / AbuseSrc / macabuse / src / net / unix / engine.hpp < prev    next >
Encoding:
C/C++ Source or Header  |  1997-05-20  |  2.1 KB  |  89 lines

  1. // engine.c is the what comminicates with the abuse engine
  2.  
  3. #ifndef __ENGINE_HPP_
  4. #define __ENGINE_HPP_
  5.  
  6. #include "../inc/netface.hpp"
  7. #include <stdio.h>
  8. #include <stdlib.h>
  9. #include <fcntl.h>
  10. #include <unistd.h>
  11. #include <sys/ioctl.h>
  12. #include <sys/stat.h>
  13. #include <sys/types.h>
  14. #include <sys/time.h>
  15. #include <string.h>
  16. #include <signal.h>
  17. #include <sys/socket.h>
  18. #include <netinet/in.h>
  19. #include <sys/types.h>
  20. #include <sys/ipc.h>
  21. #include <sys/shm.h>
  22. #include <bstring.h>
  23. #include <netdb.h>
  24.  
  25.  
  26. #define DEFAULT_COMM_PORT 20202
  27. #define DEFAULT_GAME_PORT 20203
  28. #define MAX_JOINERS 32  // maximum clients that can join at the same time                    
  29.  
  30.  
  31. extern int no_security;
  32. extern int driver_out_fd,driver_in_fd;
  33. struct base_memory_struct;
  34. extern base_memory_struct *base;
  35.  
  36.  
  37. extern fd_set master_set;        // list of sockets to block for
  38. extern fd_set master_write_set;  // set a socket here if you detect a write_full
  39.  
  40.  
  41. void comm_failed();              // call if problems talking to engine
  42. void mdie(char *reason);         // call if general net problems
  43.  
  44.  
  45. #define real2shm(type,ptr) (ptr==NULL ? NULL : ((type *)((char *)(ptr)-(char *)base)))
  46. #define shm2real(type,ptr) (ptr==NULL ? NULL : ((type *)((long)(ptr)+(long)(base))))
  47.  
  48. class client
  49. {
  50. public :
  51.   int socket_fd;
  52.   int data_fd;
  53.   int client_id;       // index into client_struct
  54.   int has_joined;
  55.   int wait_reload;
  56.   int wait_input;
  57.   int delete_me;
  58.   struct sockaddr_in data_address;  // where to send game data
  59.   
  60.   client *next;
  61.   client(int sock, int id, client *Next) 
  62.   { 
  63.     data_fd=-1;
  64.     socket_fd=sock; 
  65.     client_id=id; 
  66.     next=Next; 
  67.     has_joined=0; 
  68.     delete_me=0;
  69.     wait_reload=0;
  70.     wait_input=1;
  71.     FD_SET(socket_fd,&master_set);   // set in case socket dies
  72.   }
  73.   ~client()
  74.   {
  75.     close(socket_fd); 
  76.     FD_CLR(socket_fd,&master_set);
  77.     if (data_fd>0)
  78.       close(data_fd);
  79.   } ;
  80. } ;
  81.  
  82. extern client *first_client;    // list of clients
  83. int connect_to_server(char *&server_name, int def_port=DEFAULT_COMM_PORT, int stream_type=SOCK_STREAM, int force_port=0);  // -1 on failure
  84.  
  85. #endif
  86.  
  87.  
  88.  
  89.